home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / Sessions / Traut / ZStrings / Source / Win32 / Win32ZStringExtractTool.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-23  |  2.6 KB  |  99 lines

  1. /*==================================================================
  2.     File:        Win32ZStringExtractTool.cpp
  3.  
  4.     Contains:    Tool for extracting ZString information from
  5.                 a binary on Windows
  6.  
  7.     Written by:    Nalini Prakash
  8.                 Hayley Iben
  9.  
  10.     Copyright:    2000-2001 Connectix Corporation
  11.     
  12.     This source has been placed into the public domain by
  13.     Connectix Corporation. You have the right to modify, 
  14.     distribute or use this code without any legal limitations
  15.     or finanicial/licensing requirements. Connectix is not 
  16.     liable for any problems that result from the use of this 
  17.     code.
  18.     
  19.     If you have comments, feedback, questions, or would like
  20.     to submit bug fixes or updates to this code, please email
  21.     opensource@connectix.com.
  22. ==================================================================*/
  23.  
  24. #include "StdAfx.h"
  25. #include "ZStringTool.h"
  26.  
  27. #include "Win32ZString.h"
  28. #include "Win32ZStringTools.h"
  29. #include "Win32ZStringExtractTool.h"
  30.  
  31.  
  32. #ifdef _DEBUG
  33. #undef THIS_FILE
  34. static char THIS_FILE[]=__FILE__;
  35. #define new DEBUG_NEW
  36. #endif
  37.  
  38. //////////////////////////////////////////////////////////////////////
  39. // Construction/Destruction
  40. //////////////////////////////////////////////////////////////////////
  41.  
  42. Win32ZStringExtractTool::Win32ZStringExtractTool()
  43.     : mNewFile(INVALID_HANDLE_VALUE),
  44.     mNewMemFile(0),
  45.     mNewBinaryImage(0)
  46. {
  47. }
  48.  
  49. Win32ZStringExtractTool::~Win32ZStringExtractTool()
  50. {
  51.     // CleanUp.
  52.     if (mNewFile != INVALID_HANDLE_VALUE)
  53.         ::CloseFiles(mNewBinaryImage, mNewMemFile, mNewFile);
  54. }
  55.  
  56.  
  57. /*------------------------------------------------------------------
  58.     ExtractZStrings
  59. ------------------------------------------------------------------*/
  60.  
  61. bool
  62. Win32ZStringExtractTool::ExtractZStrings(
  63.     CString                inSrcFile, 
  64.     CString                inDestFile,
  65.     ZToolOptions        inOptions)
  66. {
  67.     Z_UInt32            newBinarySize;
  68.  
  69.     // Open as a memory mapped file.
  70.     if (!::OpenMemMappedFile(inSrcFile, mNewFile, mNewMemFile,
  71.             mNewBinaryImage, newBinarySize))
  72.     {
  73.         ::AfxMessageBox("Unable to open the source file.\n Extraction will not be completed.");
  74.         return false;
  75.     }
  76.     // Open report file. 
  77.     FILE * reportFile = fopen(inDestFile, "w+");
  78.     if (reportFile == NULL) 
  79.     {
  80.         ::AfxMessageBox("Unable to open the destination file.\n Extraction will not be completed.");
  81.         return false;
  82.     }
  83.     
  84.     CWaitCursor cursor;
  85.  
  86.     // Process the data.
  87.     ZStringTool        stringTool;    
  88.     stringTool.ProcessBinaries(mNewBinaryImage, newBinarySize, NULL, 0, inOptions); 
  89.     stringTool.PrintReport(reportFile, inOptions);
  90.  
  91.     if (mNewFile != INVALID_HANDLE_VALUE)
  92.         ::CloseFiles(mNewBinaryImage, mNewMemFile, mNewFile);
  93.     fclose(reportFile);
  94.     ::AfxMessageBox("Extraction report printed successfully.");
  95.     return true;
  96. }
  97.  
  98.  
  99.